<template>
	<div class="homelist">
		<header>
			<h2>{{proptitle}}</h2>
			<router-link to="/">更多 ></router-link>
		</header>
		<ul>
			<li v-for="(item,index) in FilterList">
				<router-link :to="`/mobile/booksdetail/${item.id}`" :key="item.id"
					v-if="(item.hot!=0 && index<6)||( item.price!=0 && index<9)">
					<img :src="`${$ip}/api/public/showimg/${item.picture}`"/>
					<h3>{{item.name}}</h3>
					<span v-show="item.price!=0">￥{{item.price.toFixed(2)}}</span>
					<span v-show="item.hot!=0">热门:{{item.hot}}</span>
				</router-link>
			</li>
		</ul>
	</div>
</template>

<script>
	export default {
		name: 'MobileHomeList',
		props: ['proplist', 'proptitle'],
		data() {
			return {
				list: []
			}
		},
		watch: {
			// 如果数据是请求获取，基本上都需要监听 props 的数据确保获取到数据后再进行循环等操作
			proplist() {

			}
		},

		computed: {
			FilterList() {
				console.log(this.proplist);
				this.list = this.porplist;
				console.log(this.list);
				//  forEachc()只做循环操作
				// nao(()=>{return}) 是一个具有返回值的回调函数
				let filters = this.proplist.map((item) => {
					return {
						id: item.id,
						name: item.memo ? item.memo : item.name,
						picture: item.picture ? item.picture : item.pic,
						price: !item.price ? 0 : item.price,
						hot: item.hot ? item.hot : 0
					}
				});
				filters.sort((a1, a2) => {
					return this.proptitle == "热门推荐" ? a2.hot - a1.hot :
						this.proptitle == '新书上市' ? a2.id - a1.id : a1.id - a2.id;
				})
				console.log(filters);
				return filters;
			}
		}
	}
</script>

<style scoped>
	.homelist {
		width: 100%;

	}

	.homelist header {
		line-height: 2.5rem;
		/* background-color: wheat; */
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.homelist header h2 {
		color: white;
		font-size: 1rem;
		margin-left: 0.5rem;
	}

	.homelist header a {
		/* 转成行内块 */
		display: inline-block;
		color: #a67b5b;
		width: 3rem;
		font-size: 0.8rem;
	}

	.homelist ul {
		width: 96%;
		margin: 0 auto 1.5rem;
		display: flex;
		align-items: center;
		justify-content: space-between;
		/* 强制换行处理 */
		flex-wrap: wrap;

	}

	.homelist ul li {
		width: 46%;
		overflow: hidden;
		margin-left: 0.6rem;
		margin-bottom: 0.5rem;
		background-color: white;
		text-align: center;
		position: relative;
	}

	.homelist ul li img {
		width: 80%;
		height: 10rem;
		margin-top: 1rem;
	}

	.homelist ul li h3 {
		width: 100%;
		height: 2.5rem;
		line-height: 2.5rem;
		font-size: 0.8rem;
		background-color: rgba(245, 213, 160, 0.5);
		color: #a68b5b;
		text-align: center;
		font-weight: normal;
		/* 中文强制不换行 */
		white-space: normal;
		overflow: hidden;
		text-overflow: ellipsis;
		/* 	支持  webkit 内核的浏览器才能生效
	font-weight: normal;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2; */
	}

	/* 中文强制不换行 */
	.homelist ul li span {
		font-size: 0.7rem;
		align-self: center;
		position: absolute;
		top: 0;
		right: 0;
		color: gold;
		padding: 0.5rem 0.3rem;
		/* 单独设置某个角 为圆角 */
		border-radius: 0 0 0 0.6rem;
	}
</style>
